package com.cwt.admin;

import cn.dev33.satoken.SaManager;
import com.cwt.common.utils.ApplicationContextUtil;
import com.cwt.common.utils.StringUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;

/**
 * @author chenwt
 * @version V1.0
 * @describe 【商城启动类】
 * @date 2023年07月17日 11:23:36
 */
@SpringBootApplication
@ComponentScan(basePackages = {"com.cwt"})
@MapperScan(basePackages = {"com.cwt.**.domain", "com.cwt.**.mapper"})
public class ShopApplication {

    private static final Logger logger = LoggerFactory.getLogger(ShopApplication.class);

    public static void main(String[] args) throws InterruptedException {
        logger.warn("项目开始启动 >> 打印【项目启动完成】后启动成功");
        ConfigurableApplicationContext context = SpringApplication.run(ShopApplication.class, args);
        ApplicationContextUtil.setApplicationContext(context);
        logger.info("========== >> 设置 ApplicationContext 成功");
        Environment environment = context.getEnvironment();
        String path = environment.getProperty("server.servlet.context-path");
        String port = environment.getProperty("server.port");
        logger.info("-----------------------------------------------------------");
        if (StringUtils.isEmpty(path)) {
            path = "";
            logger.info("========== >> boot 访问地址统一前缀：{}", path);
        }
        logger.info("========== >> boot 访问地址：url >> http://{}:{}{}", "localhost", port, path);
        logger.info("-----------------------------------------------------------");

        // sleep 三秒之后，启动成功
        Thread.sleep(1000L);
        logger.warn("项目启动完成");
        logger.info("启动成功，Sa-Token 配置如下：" + SaManager.getConfig());
    }

}
